package com.zdy.ProxyStaitc;

/**
 * Created by 逸足天涯
 * on 3/8/2020.
/*
* 静态代理
 * 真实对象和dialing对象都实现同一个接口

 * 代理对象代理真实的角色
 * 好处：
 *      代理对象做真实对象做不来的事
 *      真实对象专注做自己的事
*
* */
public interface Marry {
    void happyMarry();
}
//真实角色
class You implements Marry{

    @Override
    public void happyMarry() {
        System.out.println("你要结婚了真开心");
    }
}
//代理角色
class WeddingCompany implements Marry{
    private You you;

    public WeddingCompany(You you) {
        this.you = you;
    }

    @Override
    public void happyMarry() {
        before();
        you.happyMarry();
        after();
    }

    private void before() {
        System.out.println("布置现场");
    }

    private void after() {
        System.out.println("处理现场，收取尾款");
    }
}
//实现场景
class Client{
    public static void main(String[] args) {
        You you = new You();
        WeddingCompany wc = new WeddingCompany(you);
        wc.happyMarry();

       /* //多线程
        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("我要搞事情了");
            }
        }).start();*/

       /* *//*Lamda表达式形式*//*
        new Thread(()-> System.out.println("我要搞事情了")).start();*/

        new WeddingCompany(new You()).happyMarry();

    }

}